//$CC PDO_config.c -o ectest_pdo -L /home/lee/test -lethercat
//scp ectest_pdo root@192.168.58.1:/home/mc
#include "config_qn.h"
/*****************************************************************************/

void check_master_state(void)
{
    ec_master_state_t ms;

    ecrt_master_state(master, &ms);

    if (ms.slaves_responding != master_state.slaves_responding) {
        printf("%u slave(s).\n", ms.slaves_responding);
    }
    if (ms.al_states != master_state.al_states) {
        printf("AL states: 0x%02X.\n", ms.al_states);
    }
    if (ms.link_up != master_state.link_up) {
        printf("Link is %s.\n", ms.link_up ? "up" : "down");
    }

    master_state = ms;
}  
/*****************************************************************************/
int main(void)
{
    
    printf("hello world!\n");
    //sleep(1);
    master = ecrt_request_master(0);
    if (!master) {
        return -1;
    }
    printf("request_master sucess\n");
    check_master_state();
    //check_slave_config_states();
    
    int n,i;
    printf("xenomai Creating slave0 configurations...\n");
    sc_cooldrive =
       ecrt_master_slave_config(master,CoolDrivePos0,CoolDrive);
    if (!sc_cooldrive ) {
        fprintf(stderr, "Failed to get slave0 configuration.\n");
        return -1;
    }
    else printf("get right slave0 config sc_cooldrive\n");
    
    i=0;
    do
    {
    	
    	sleep(3);    	
    	n=ecrt_slave_config_pdos(sc_cooldrive, EC_END, slave_0_syncs);
    	i++;
    	if(i>5){
    		printf("slave0 configurations is outtime\n");
    		break;
    	}
    }
    while(n);
    printf("slave0 configurations is ok\n");
    
    printf("release_master\n");
    ecrt_release_master(master);
    //pause();
    return 0;
}


















